import React, {Component} from 'react';
import GrandParentContext from "./utils/GrandParentContext";
import Son from "./views/Son";
import style from './Parent.module.css'

console.log(style);
class Index extends Component {
  state = {
    obj: {
      name: '张张',
      age: 19
    },
    fromChild: ''
  };

  callback = (msg) => {
    console.log(msg)
    this.setState({
      fromChild: msg
    })
  };
  render() {
    return (
      /*值传到子组件 必须用value*/
      <GrandParentContext.Provider value={this.state.obj}>
        {/*<Parent/>*/}
        <Son toChild={this.callback}/>
        <br/>
        <h1 id={style.parent} className={style.active}>abcdef{this.state.fromChild}</h1>
      </GrandParentContext.Provider>
    );
  }
}

export default Index;
